import request from '@/utils/request';
import { formatDateToString } from '@/utils/index';

export function getTotalOrderData({ times, pageNum, pageSize }) {
    return request({
        url: '/v1/order/summmary/total',
        method: 'post',
        data: {
            startDate: formatDateToString(times[0]),
            endDate: formatDateToString(times[1]),
            pageNum,
            pageSize
        }
    });
}

export function getDetailOrderData({ times, pageNum, pageSize }) {
    return request({
        url: '/v1/order/summmary/detail',
        method: 'post',
        data: {
            startDate: formatDateToString(times[0]),
            endDate: formatDateToString(times[1]),
            pageNum,
            pageSize
        }
    });
}

export function getDetailGoodsData({ times, pageNum, pageSize, orderBy, nameOrCode }) {
    return request({
        url: '/v1/goods/sale/activity/summary/list',
        method: 'post',
        data: {
            startDate: formatDateToString(times[0]),
            endDate: formatDateToString(times[1]),
            pageNum,
            pageSize,
            orderBy,
            nameOrCode: !!nameOrCode ? nameOrCode : undefined
        }
    });
}

export function getDetailStoreData({ times, pageNum, pageSize, orderBy }) {
    return request({
        url: '/v1/member/summary/list',
        method: 'post',
        data: {
            startDate: formatDateToString(times[0]),
            endDate: formatDateToString(times[1]),
            pageNum,
            pageSize,
            orderBy
        }
    });
}

export function getDetailComData({ times, pageNum, pageSize, orderBy, searchWords }) {
    return request({
        url: '/v1/head/summary/list',
        method: 'post',
        data: {
            startDate: formatDateToString(times[0]),
            endDate: formatDateToString(times[1]),
            pageNum,
            pageSize,
            orderBy,
            searchWords: !!searchWords ? searchWords : undefined
        }
    });
}
